package com.wilmer.pay.controller;

import com.wilmer.common.annotation.Anonymous;
import com.wilmer.common.core.domain.AjaxResult;
import com.wilmer.common.utils.SecurityUtils;
import com.wilmer.pay.domain.conPayVo;
import com.wilmer.pay.domain.payVo;
import com.wilmer.pay.service.wechatPayService;
import com.wilmer.videoOrder.domain.dto.VideoOrderPayDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Scope;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * <p>微信支付接口</p>
 * @author hans
 */
@Slf4j

@RestController
@Scope("prototype")
@Api(tags = "微信支付接口")
@RequestMapping("/api/wx/pay/v3")
public class weChatPayController {


    @Resource
    private wechatPayService wechatPayService;


    @ApiOperation("支付接口，传入金额和wx.login的code")
    @Anonymous()
    @PostMapping("/payCon")
    @ResponseBody
    public  AjaxResult v3PayCon(@RequestBody conPayVo payVo) throws Exception{
        return wechatPayService.v3PayCon(payVo);
    }

    @ApiOperation("支付接口，传入金额和wx.login的code")
    @Anonymous()
    @PostMapping("/payAi")
    @ResponseBody
    public  AjaxResult v3Pay(@RequestBody payVo payVo) throws Exception{
        return wechatPayService.v3Pay(payVo);
    }

    @ApiOperation("支付接口，传入订单编号")
    @PostMapping("/videoPay")
    @ResponseBody
    public  AjaxResult videoPay(@RequestBody VideoOrderPayDto dto) throws Exception{
        return wechatPayService.videoPay(dto);
    }
    /**
     * 微信支付回调
     * @param request
     * @param response
     */
    @Anonymous
    @RequestMapping(value = "/payNotify", method = {RequestMethod.POST, RequestMethod.GET})
    public AjaxResult payNotify(HttpServletRequest request, HttpServletResponse response) {
        wechatPayService.payNotify(request,response);
        return AjaxResult.success();
    }
    @Anonymous
    @RequestMapping("/get")
    @ResponseBody
    public String v3Get() {
        return wechatPayService.v3Get();
    }

}
